package com.thoughtworks.jsstaticanalysis;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class JavascriptSummary {

    private List<JavascriptFileSummary> summaries = new ArrayList<JavascriptFileSummary>();
    private String entrance;

    public JavascriptSummary(String entrance) {
        this.entrance = entrance;
        File file = new File(entrance);
        summaryForFile(file);
    }

    private void summaryForFile(File file) {
        if (file.isFile()) {
            if (file.getName().endsWith(".js")) {
                JavascriptFileSummary summary = new JavascriptFileSummary(file);
                summaries.add(summary);
            }
        } else {
            File[] children = file.listFiles();
            for (File child : children) {
                summaryForFile(child);
            }
        }
    }

    public List<JavascriptFileSummary> getAllFileSummaries() {
        return summaries;
    }

    public String getEntrance() {
        return entrance;
    }
}
